package com.egao.oa.controller;

import com.egao.common.core.damon.results.PageResult2;
import com.egao.common.core.web.*;
import com.egao.common.core.annotation.OperLog;
import com.egao.common.system.entity.DictionaryData;
import com.egao.common.system.service.DictionaryDataService2;
import com.egao.oa.entity.PhoneBook;
import com.egao.oa.service.PhoneBookService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.ui.Model;


/**
 *
 * 通讯录
 * @author : Doman
 * @date : 2020-08-19 10:53:21
 * @version ：1.0
 */

@Controller
@RequestMapping("/oa/phoneBook")
public class PhoneBookController extends BaseController {

	@Autowired
	private PhoneBookService phoneBookService;
    @Autowired
    private DictionaryDataService2 dictionaryDataService2;
	
	/**
	 * 页面
	 **/
	@RequiresPermissions("oa:phoneBook:view")
	@RequestMapping()
	public String view(Model model) {
        model.addAttribute("bookPositionList",dictionaryDataService2.listAllByDictCode(new DictionaryData("book_position")));
		return "oa/phoneBook.html";
	}

	/**
	 * 分页查询列表
	 */
	@RequiresPermissions("oa:phoneBook:list")
	@OperLog(value = "通讯录", desc = "分页查询")
	@ResponseBody
	@RequestMapping("/page")
    public JsonResult list(PageResult2<T> page, PhoneBook phoneBook) throws Exception{
        return phoneBookService.list(page, phoneBook, getLoginUser());
    }

    /**
     * 查询全部通讯录
     */
    @RequiresPermissions("oa:phoneBook:list")
    @OperLog(value = "通讯录", desc = "查询全部")
    @ResponseBody
    @RequestMapping("/list")
    public JsonResult list(PhoneBook phoneBook){
        return JsonResult.ok().setData(phoneBookService.list(phoneBook, getLoginUser()));
    }

    /**
     * 根据id查询通讯录
     */
    @RequiresPermissions("oa:phoneBook:list")
    @OperLog(value = "通讯录", desc = "根据id查询")
    @ResponseBody
    @RequestMapping("/get")
    public JsonResult get(PhoneBook phoneBook) {
        return phoneBookService.getById(phoneBook);
		// 使用关联查询
        //PageParam<phoneBook> pageParam = new PageParam<>();
		//pageParam.put("id", id);
        //List<phoneBook> records = phoneBookService.listAll(pageParam.getNoPageParam());
        //return JsonResult.ok().setData(pageParam.getOne(records));
    }


    /**
     * 添加通讯录
     */
    @RequiresPermissions("oa:phoneBook:save")
    @OperLog(value = "通讯录", desc = "添加", param = false, result = true)
    @ResponseBody
    @RequestMapping("/save")
    public JsonResult save(Model model, PhoneBook phoneBook) {
        return phoneBookService.save(phoneBook, getLoginUser());
    }

    /**
     * 修改通讯录
     */
    @RequiresPermissions("oa:phoneBook:update")
    @OperLog(value = "通讯录", desc = "修改", param = false, result = true)
    @ResponseBody
    @RequestMapping("/update")
    public JsonResult update(Model model, PhoneBook phoneBook) {
        return phoneBookService.update(phoneBook, getLoginUser());
    }

    /**
     * 删除通讯录
     */
    @RequiresPermissions("oa:phoneBook:remove")
    @OperLog(value = "通讯录", desc = "删除", result = true)
    @ResponseBody
    @RequestMapping("/remove")
    public JsonResult remove(PhoneBook phoneBook ) {
        return phoneBookService.remove(phoneBook, getLoginUser());
    }

    /**
     * 批量添加通讯录
     */
    /**@RequiresPermissions("oa:phoneBook:save")
    @OperLog(value = "通讯录", desc = "批量添加", param = false, result = true)
    @ResponseBody
    @RequestMapping("/saveBatch")
    public JsonResult saveBatch(@RequestBody List<PhoneBook> list) {
        if (phoneBookService.saveBatch(list)) {
            return JsonResult.ok("添加成功");
        }
        return JsonResult.error("添加失败");
    }*/

    /**
     * 批量修改通讯录
     */
    /**@RequiresPermissions("oa:phoneBook:update")
    @OperLog(value = "通讯录", desc = "批量修改", result = true)
    @ResponseBody
    @RequestMapping("/updateBatch")
    public JsonResult updateBatch(@RequestBody BatchParam<PhoneBook> batchParam) {
        if (batchParam.update(phoneBookService, "")) {
            return JsonResult.ok("修改成功");
        }
        return JsonResult.error("修改失败");
    }*/

    /**
     * 批量删除通讯录
     */
    /**@RequiresPermissions("oa:phoneBook:remove")
    @OperLog(value = "通讯录", desc = "批量删除", result = true)
    @ResponseBody
    @RequestMapping("/removeBatch")
    public JsonResult removeBatch(@RequestBody List<Integer> ids) {
        if (phoneBookService.removeByIds(ids)) {
            return JsonResult.ok("删除成功");
        }
        return JsonResult.error("删除失败");
    }*/

}
